<?php
//ini_set('error_reporting', 6143);
//ini_set('display_errors','1');
define('IN_LC', true);
define('MM_ID', 1);

include_once("validate.php");
include_once("includes/style.php");
include_once("includes/addMessage.php");

$style = new style(true);

// are we logging out?
if(isset($_GET['action']) && $_GET['action'] == 'logout')
{
	include_once("includes/user_logout.php");
	$logout = new user_logout();
	$style->addRenderRight($logout);
}

// are we logging in?
else if(isset($_GET['action']) && $_GET['action'] == 'login')
{
	include_once("includes/user_login.php");
	$login = new user_login();
	$style->addRenderRight($login);
}


	include_once('includes/renderInclude.php');
	include_once('includes/addMessage.php');
	include_once("includes/news.php");
	
	$q = "SELECT *, DATE_FORMAT(n_posteddate, '%W %D %M %Y, %l:%i%p')  as n_posteddateF,
						 (n_stickyexpiry > NOW()) as n_showsticky, COUNT(co_id) as comment_count
		  FROM " . CATAGORIES_TABLE . ", " . NEWSARTICLES_TABLE . " 
		  LEFT JOIN " . COMMENTS_TABLE . " ON n_id = co_catagory_item AND co_catagory = 3 
		  WHERE c_id = n_catagory AND c_newscat = 1 AND n_enabled = 1
		  GROUP BY n_id
		  ORDER BY n_showsticky DESC, n_posteddate DESC
		  LIMIT 0, 10";
	$result = $db->sql_query($q);
		
	$style->addRenderRight(new addMessage(sprintf($lang['WelcomeText'],'news.php'), '<a href="news.php">' . $lang['WelcomeTextTitle'] . '</a>'));
	$style->addRenderRight(new renderInclude('tpl/tableStart.tpl'));
	
	while($news_article = $db->sql_fetchrow($result)) 
	{
		$article = new news(false, $news_article, NEWS_MODE_MINI);
		if($article->ok())
		{
			$style->addRenderRight($article);
		}
	}
	
	$style->addRenderRight(new renderInclude('tpl/tableEnd.tpl'));
	
	
	
	
	
	include_once('includes/latest_results.php');
	$style->addRenderLeft(new random_champion());
	$style->addRenderLeft(new random_result());
	$style->addRenderLeft(new random_championship());
	$style->addRenderLeft(new random_event());
	

$style->render();

echo $db->num_queries;
?>